{% extends "announcements/announcements.html" %}

{% block page_link %}
    <script src="../../static/announcements/js/management.js"></script>
    <link rel="stylesheet" href="../../static/announcements/css/style.css">
    <link rel="stylesheet" href="../../static/system_setup/css/style.css">
    <link rel="stylesheet" type="text/css" href="../../static/personal_center/css/index.css">
    <link rel="stylesheet" type="text/css" href="../../static/personal_center/css/common.css">
    <script type="text/javascript" src="../../static/personal_center/js/index.js"></script>
{% endblock %}


{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }

        tr {
            height: 35px;
        }

        th {
            text-align: center;
        }
    </style>
{% endblock %}


{% block right_content %}
    <div style="display: inline-block;vertical-align: top;width: 100%;height: 100%;">
        <div class="headline">
            <div style="width: 10%;height: 100%;line-height: 40px;display: inline-block;">
                <a href="administration.html" style="color: #0b0b0b;">
                    <i class="iconfont icon-tongzhigonggao"></i>
                    <span> 通知公告</span>
                </a>
            </div>
        </div>
        <div id="my_application" style="width: 100%;height: 95.3%;overflow: auto;background-color: white;">
            <div class="right-box" style="width: 100%;height: 100%;margin-top: 0;">
                <div style="height: 100%;width: 100%;overflow: auto;border-bottom: #cccccc solid 1px;background-color: white;">
                    <section class="grid-main" style="height: 100%;">
                        <table id="main_table"></table>
                    </section>
                </div>
            </div>
        </div>
    </div>

    <!--确认删除？-->
    <div class="modal fade bd-example-modal-sm" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-sm" style="margin-top: 10%;">
            <div class="modal-content"
                 style="height: 150px;border-radius: 7px;width: 300px;background: #F8F8FF;border: #1E90FF solid 1px;">
                <div class="modal-header"
                     style="height: 40px;background: #1E90FF;border-top-left-radius: 7px;border-top-right-radius: 7px;">
                    <h5 class="modal-title" style="line-height: 40px;width: 40%;text-align: center;color: #ffffff;">
                        提示对话框
                    </h5>
                    <button id="close-model2" type="button" class="close" data-dismiss="modal" aria-label="Close"
                            style="margin-right: 3%;line-height: 40px;">
                        <span aria-hidden="true" style="font-size: 28px;color: white;">&times;</span>
                    </button>
                </div>
                <div class="modal-body" style="height: 50px;line-height: 60px;text-align: center;">
                    <p id="Confirm-content"></p>
                </div>
                <div class="modal-footer" style="height: 40px;">
                    <button onclick="delete_notice()" type="button" class="btn btn-primary" aria-label="Close"
                            style="margin-left: 2%;margin-right: 2%;background: #1E90FF;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;确&nbsp;认&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </button>
                </div>
            </div>
        </div>
    </div>

{% endblock %}




{% block script %}
    <script src="../../static/public_file/js/jquery.min.js"></script>
    <script src="../../static/system_setup/js/jquery.ztree.all.min.js"></script>
    <script src="../../static/system_setup/js/django.ajax.post.csrf.js"></script>
    <script type="text/javascript" src="../../static/administrative/js/layer.js"></script>
    <script>
        window.onload = function () {
            document.getElementById("loading").style.display = "none";
            document.getElementById("inform").className = "add_class";
            document.getElementById("Announcement-management1").className = "add-nav-active";
        };
        {#var data_list = {{ data_list | safe }};#}
        {#var data_len = {{ data_len | safe }};#}
        {#console.log(data_list);#}
        {#create_fun(data_list);#}
        {#pagenum(data_len, 1);#}


        {#function create_fun(data_list) {#}
        {#    if (!data_list.length) {#}
        {#        document.getElementById("img-display").style.display = "inline-block";#}
        {#    } else {#}
        {#        var t_table = document.getElementById("t_table");#}
        {#        deltr();#}
        {#        for (var i = 0; i < data_list.length; i++) {#}
        {#            var tr = document.createElement("tr");#}
        {#            if (data_list[i]["status"] === 'accepted') {#}
        {#                tr.style.color = '#949494';#}
        {#            }#}
        {#            if (data_list[i]["status"] === 'accept') {#}
        {#                tr.style.color = '#363636';#}
        {#            }#}
        {#            var td = document.createElement("td");#}
        {#            td1 = document.createElement("td");#}
        {#            td2 = document.createElement("td");#}
        {#            td3 = document.createElement("td");#}
        {#            td4 = document.createElement("td");#}
        {#            td.innerHTML = data_list[i]["titile"];#}
        {#            td.style.paddingLeft = "2%";#}
        {#            td1.innerHTML = data_list[i]["department"];#}
        {#            td1.style.textAlign = "center";#}
        {#            td2.innerHTML = data_list[i]["create_user"];#}
        {#            td2.style.textAlign = "center";#}
        {#            td3.innerHTML = data_list[i]["create_time"];#}
        {#            td3.style.textAlign = "center";#}
        {#            td4.innerHTML = "<a href='notice_detail.html?type=all&id=" + data_list[i]["id"] + "'>查看</a>";#}
        {#            td4.style.textAlign = "center";#}
        {#            tr.appendChild(td);#}
        {#            tr.appendChild(td1);#}
        {#            tr.appendChild(td2);#}
        {#            tr.appendChild(td3);#}
        {#            tr.appendChild(td4);#}
        {#            t_table.appendChild(tr);#}
        {#        }#}
        {#    }#}
        {# }#}

        const gridManagerName = "test",
            TYPE_MAP = {1: "HTML/CSS", 2: "nodeJS", 3: "javaScript", 4: "前端鸡汤", 5: "PM Coffee", 6: "前端框架", 7: "前端相关"},
            arg = {
                gridManagerName: "test",
                width: "100%",
                height: "100%",
                autoOrderConfig: {fixed: "left"},
                checkboxConfig: {key: "id", fixed: "left"},
                supportAjaxPage: !0,
                sortMode: "single",
                supportMenu: !0,
                menuHandler: e => (e.unshift({
                    content: "自定义菜单", line: !0, onClick: e => {
                        alert(e)
                    }
                }), e),
                useCellFocus: !0,
                useHideRow: !0,
                supportMoveRow: !0,
                moveRowConfig: {
                    key: "priority", useSingleMode: !0, fixed: "left", handler: (e, t) => {
                        console.log(e, t)
                    }
                },
                disableCache: !1,
                ajaxData: function (e, t) {
                    var local_host = window.location.host;          // 获取当前IP
                    return "/announcements/administration.html"
                },
                exportConfig: {
                    fileName: e => {
                        const t = new Date;
                        let a = `${t.getFullYear()}-${t.getMonth() + 1}-${t.getDate()}`;
                        for (let t in e) a = `${a}-${t}=${e[t]}`;
                        return a
                    }, suffix: "xls"
                },
                ajaxType: "POST",
                rowRenderHandler: (e, t) => e,
                emptyTemplate: e => `<div style="text-align: center;">${e.query.title ? "搜索为空" : "暂无数据"}</div>`,
                columnData: [
                    {
                        key: "titile",
                        text: "公告名称",
                        align: "center",
                        disableMoveRow: !0
                    }, {
                        key: "department",
                        text: "发布部门",
                        align: "center",
                    }, {
                        key: "create_user",
                        text: "发布人",
                        align: "center",
                    }, {
                        key: "is_open",
                        text: "是否公开",
                        align: "center",
                    }, {
                        key: "create_time",
                        text: "申请时间",
                        align: "center",
                    }, {
                        key: "action",
                        width: "100px",
                        align: "center",
                        fixed: "right",
                        disableMoveRow: !0,
                        disableRowCheck: !0,
                        text: '<span style="color: red">操作</span>',
                        template: (e, t) => `<a class="plugin-action" id="${t.id}" href="notice_detail.html?type=all&id=${t.id}" onclick="">查看</a>`
                    }]
            }, demo1 = {
                initSearch: function () {
                }, initFN: () => {

                }, initGM: function () {
                    new window.GridManager(table, arg, (e => {
                    }))
                }, editRowData: function (e) {
                    window.GridManager.updateRowData("test", "id", {
                        id: window.parseInt(e.getAttribute("data-id")),
                        lastDate: (new Date).getTime()
                    })
                }
            }, table = document.querySelector("#main_table");
        demo1.initSearch(table), demo1.initGM(table), demo1.initFN();


        // 删除列表
        function deltr() {
            var tb = document.getElementById('t_table');
            var rowNum = tb.rows.length;
            for (i = 0; i < rowNum; i++) {
                tb.deleteRow(i);
                rowNum = rowNum - 1;
                i = i - 1;
            }
        }

        function request_fun(page = 1, search = 0) {
            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('get', "/announcements/administration.html?page=" + String(page) + "&search=" + String(search));
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
            xhr.send();
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        create_fun(JsonDate["data_list"]);
                        pagenum(JsonDate["data_len"], page);
                    }
                }
            };
        }

        function pagenum(dataTotals = 0, page = 1) {
            new myPagination({
                id: 'pagination',
                curPage: page, //初始页码
                pageAmount: 20,  //每页多少条
                dataTotal: dataTotals, //总共多少条数据
                pageTotal: Math.ceil(parseInt(dataTotals, 10) / 20), //总页数
                pageSize: 5, //可选,分页个数
                showPageTotalFlag: true, //是否显示数据统计
                showSkipInputFlag: true, //是否支持跳转
                getPage: function (page) {
                    request_fun(page, 1);
                }
            });
        }

        function permissions_validation(a_href, permissions_type) {
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/system-setup/permissions_validation");
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
            xhr.send("permissions_type=通知公告");
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        var permissions_flag = false;

                        for (var key in JsonDate["permissions"]) {
                            if (JsonDate["permissions"][key]) {
                                permissions_flag = true;
                                break
                            }
                        }
                        if (permissions_flag) {
                            window.location.href = a_href;
                        }
                        if (!permissions_flag) {
                            alert("您的访问权限不足！")
                        }
                    }
                }
            };
        }
    </script>
{% endblock %}
